//
//  CheckDetailViewController.m
//  MyProject
//
//  Created by Pei on 16/6/29.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

/*
 {
 Error = "";
 ErrorCode = "";
 InspectContentList =     (
 {
 InspectContentID = 726;
 InspectContentName = "\U6253\U6869\U8fdd\U7ae0\U64cd\U4f5c";
 MaxPoints = 10;
 },
 {
 InspectContentID = 727;
 InspectContentName = "\U8d85\U9ad8\U9650\U4f4d\U88c5\U7f6e\U5931\U7075";
 MaxPoints = 10;
 }
 );
 InspectItemCode = "GKYHAGC_SSZJSG_SWXW";
 InspectItemID = 298;
 InspectItemName = "\U6c34\U4e0a\U6869\U57fa\U65bd\U5de5";
 InspectType = 1;
 RiskType = 0;
 Success = 1;
 }
 */

#import "CheckDetailViewController.h"
#import "IHRefreshTableView.h"
#import "CheckDetailCell.h"
#import "WriteCheckItemDetailViewController.h"

@interface CheckDetailViewController ()<UITableViewDataSource, UITableViewDelegate, WriteCheckItemDetailViewControllerDelegate>
{
    IHRefreshTableView *_myTable;
    
    UIView *_headerView;
    
    NSDictionary *_currentDic;
    
    NSArray *_dataArray;
    
    NSMutableArray *_pointsArray;
    
    //SelectModel *_currentModel;
    
    NSDictionary *_InspectOrgAndProjectDic;
    NSDictionary *_checkDic;
    
    UIDatePicker *_datePicker;
    UIView *_dateTopView;
    NSString *_dateStr;
    UILabel *detailLbl6;
    
    NSString *nameStr;
}

@end

@implementation CheckDetailViewController

//- (instancetype)initWithModel:(SelectModel*)model
- (instancetype)initWithModel:(NSDictionary*)model projectAndCompany:(NSDictionary*)_InspectOrgAndProjectDicT checkType:(NSDictionary*)_checkDicT
{
    self = [super init];
    if(self){
        //[self getData:[[model valueForKey:@"InspectItemID"] intValue]];
        _currentDic = model;
        
        _InspectOrgAndProjectDic = _InspectOrgAndProjectDicT;
        _checkDic = _checkDicT;
        
        _dataArray = [_currentDic valueForKey:@"InspectContentList"];
        
        NSDictionary *dateRRRR = [_dataArray objectAtIndex:0];
        _dateStr = [dateRRRR valueForKey:@"JieZhiDate"];
        nameStr = [dateRRRR valueForKey:@"InspectTaskNameCustom"];
        
        if (_dateStr != nil && _dateStr.length > 0) {
            _dateStr = [dateRRRR valueForKey:@"JieZhiDate"];
        }else{
            NSDate *afterDate = [NSDate dateWithTimeIntervalSinceNow:3*24*60*60];
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            // 格式化日期格式
            formatter. dateFormat = @"yyyy-MM-dd" ;
            _dateStr = [formatter stringFromDate:afterDate];
        }
        
        NSMutableArray *tempA = [[NSMutableArray alloc] initWithCapacity:3];
        [tempA removeAllObjects];
        for (NSDictionary *tempD in _dataArray) {
            NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:tempD];
            
            NSString *JianChaMiaoShuStr = [tempD valueForKey:@"JianChaMiaoShu"];
            if (JianChaMiaoShuStr != nil && JianChaMiaoShuStr.length > 0) {
                
            }else{
               [dic setValue:@"" forKey:@"JianChaMiaoShu"];
            }
            
            NSString *KouFenStr = [tempD valueForKey:@"KouFen"];
            if (KouFenStr != nil && [KouFenStr intValue] > 0) {
                
            }else{
                [dic setValue:@"0" forKey:@"KouFen"];
            }
            
            NSDictionary *RiskLeveDic = [tempD valueForKey:@"RiskLevel_Dic"];
            if (RiskLeveDic != nil && RiskLeveDic.count > 0) {
                
            }else{
                [dic setValue:@[] forKey:@"RiskLevel_Dic"];
            }
            
            
            NSArray *ImageDataAry = [tempD valueForKey:@"ImageData_List"];
            if (ImageDataAry != nil && ImageDataAry.count >0) {
                
            }else{
               [dic setValue:@[] forKey:@"ImageData_List"]; 
            }
            //[dic setValue:@"" forKey:@"JieZhiDate"];
            
            
            [tempA addObject:dic];
        }
        
        _dataArray = tempA;
        
        
        [self initTableView];
        [self initTableHeaderView];
    }
    return self;
    
}

- (instancetype)initWithInspectContentID:(int)id
{
    self = [super init];
    if(self){
        [self getData:id];
    }
    return self;
}

- (void)getData:(int)id
{
    [[YMNetLib getInstance] connectWithAction:Get_InspectItem_Detail_API method:@"GET" withContent:[NSString stringWithFormat:@"InspectItemID=%d", id] withBody:nil withDelegate:self];
}

- (void)NetDoOverSuccess:(NSDictionary*)body
{
    if ([[YMNetDataUtil getSuccessState:body] intValue] == 1)
    {
        //        _currentDic = body;
        //
        ////        if (![[_currentDic valueForKey:@"InspectContentList"] isEqualToString:@""]) {
        ////            _dataArray = [_currentDic valueForKey:@"InspectContentList"];
        ////        }
        //        _dataArray = [_currentDic valueForKey:@"InspectContentList"];
        //        NSMutableArray *tempA = [[NSMutableArray alloc] initWithCapacity:3];
        //        for (NSDictionary *tempD in _dataArray) {
        //            NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:tempD];
        //            [dic setValue:@"无" forKey:@"JianChaMiaoShu"];
        //            [dic setValue:@"0" forKey:@"KouFen"];
        //            [tempA addObject:dic];
        //        }
        //
        //        _dataArray = tempA;
    }
    
    //    [self initTableView];
    //    [self initTableHeaderView];
}


- (void)viewDidLoad {
    self.navTitle = @"检查单详情";
    [super viewDidLoad];
    
    
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 22)];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = kAppFont(Home_Big_Size);
    [rightBtn addTarget:self action:@selector(rightBtnAcion) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:rightBtn]];
    
    _pointsArray = [[NSMutableArray alloc] initWithCapacity:3];
    
    
    
}

- (void)rightBtnAcion{
    NSMutableDictionary *saveDic = [[NSMutableDictionary alloc] initWithDictionary:_currentDic];
    
    NSMutableArray *tempData = [[NSMutableArray alloc] initWithCapacity:3];
    [tempData removeAllObjects];
    
    for (NSDictionary *nary in _dataArray) {
        NSMutableDictionary *dateNary = [[NSMutableDictionary alloc] initWithDictionary:nary];
        [dateNary setValue:_dateStr forKey:@"JieZhiDate"];
        [dateNary setValue:nameStr forKey:@"InspectTaskNameCustom"];
        [tempData addObject:dateNary];
    }
    
    _dataArray = tempData;
    
    [saveDic setObject:_dataArray forKey:@"InspectContentList"];
    
    if ([self.delegate respondsToSelector:@selector(passCheckDetailDic:)]) {
        [self.delegate passCheckDetailDic:saveDic];
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)navigationBack
{
    /*
     if (_dataArray != nil && _dataArray.count > 0) {
     _currentModel.pointArray = _dataArray;
     if ([self.delegate respondsToSelector:@selector(passModel:)]) {
     [self.delegate passModel:_currentModel];
     }
     }
     */
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)initTableView
{
    CGRect frame = CGRectMake(0, 0.0f, kDeviceWidth, kDeviceHeight-NAV_HEIGHT);
    _myTable = [[IHRefreshTableView alloc] initWithFrame:frame refreshType:-1 andAutoLoad:NO];
    _myTable.delegate = self;
    _myTable.dataSource = self;
    _myTable.footer.hidden = YES;
    _myTable.header.hidden = YES;
    [self.view addSubview:_myTable];
}

- (void)initTableHeaderView
{
    _headerView = [[UIView alloc] init];
    _headerView.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, 54.0f*7);
    _headerView.backgroundColor = kWhiteColor;
    _myTable.tableHeaderView = _headerView;
    
    
    UILabel *lbl0 = [[UILabel alloc] init];
    lbl0.frame = CGRectMake(10.0, (54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl0.font = kAppFont(Home_Small_Size+2.0f);
    lbl0.textColor = kRGB(205, 206, 207);;
    lbl0.text = @"任务名称";
    [_headerView addSubview:lbl0];
    
    
    UIImageView *arrowImageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView0.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, (54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[_headerView addSubview:arrowImageView0];
    
    UILabel *detailLbl0 = [[UILabel alloc] init];
    detailLbl0.frame = CGRectMake(lbl0.right+5.0f, (54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl0.width-5.0f-10.0f, Home_Big_Size);
    detailLbl0.textColor = kRGB(100, 99, 104);
    detailLbl0.font = kAppFont(Home_Small_Size);
    detailLbl0.textAlignment = NSTextAlignmentRight;
    
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *currentTime = [formatter stringFromDate:[NSDate date]];
    
    if (nameStr != nil && nameStr.length > 0) {
       detailLbl0.text = nameStr;
    }else{
       detailLbl0.text = [NSString stringWithFormat:@"检查任务-%@", currentTime];//[_currentDic valueForKey:@"InspectItemName"];
        nameStr = [NSString stringWithFormat:@"检查任务-%@", currentTime];
    }
    
    
    [_headerView addSubview:detailLbl0];
    
    
    
    UIView *lineView0 = [[UIView alloc] init];
    lineView0.frame = CGRectMake(0.0f, 54.0f-0.5f, kDeviceWidth, 0.5f);
    lineView0.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView0];
    
    
    NSDictionary *tempSuperDic = [_currentDic objectForKey:@"superDic"];
    
    UILabel *lbl1 = [[UILabel alloc] init];
    lbl1.frame = CGRectMake(10.0, lineView0.bottom+(54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl1.font = kAppFont(Home_Small_Size+2.0f);
    lbl1.textColor = kRGB(205, 206, 207);;
    lbl1.text = @"检查专业";
    [_headerView addSubview:lbl1];
    
    
    //UIImageView *arrowImageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    //arrowImageView0.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, (54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[_headerView addSubview:arrowImageView0];
    
    UILabel *detailLbl1 = [[UILabel alloc] init];
    detailLbl1.frame = CGRectMake(lbl1.right+5.0f, lineView0.bottom+(54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl1.width-5.0f-10.0f, Home_Big_Size);
    detailLbl1.textColor = kRGB(100, 99, 104);
    detailLbl1.font = kAppFont(Home_Small_Size);
    detailLbl1.textAlignment = NSTextAlignmentRight;
    detailLbl1.text = [tempSuperDic valueForKey:@"SpecialtyName"];
    [_headerView addSubview:detailLbl1];
    
    UIView *lineView1 = [[UIView alloc] init];
    lineView1.frame = CGRectMake(0.0f, 54.0f*2.0f-0.5f, kDeviceWidth, 0.5f);
    lineView1.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView1];
    
    
    
    
    
    UILabel *lbl2 = [[UILabel alloc] init];
    lbl2.frame = CGRectMake(10.0, lineView1.bottom +(54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl2.font = kAppFont(Home_Small_Size+2.0f);
    lbl2.textColor = kRGB(205, 206, 207);;
    lbl2.text = @"检查项";
    [_headerView addSubview:lbl2];
    
    
    //UIImageView *arrowImageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    //arrowImageView0.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, (54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[_headerView addSubview:arrowImageView0];
    
    UILabel *detailLbl2 = [[UILabel alloc] init];
    detailLbl2.frame = CGRectMake(lbl2.right+5.0f, lineView1.bottom+(54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl2.width-5.0f-10.0f, Home_Big_Size);
    detailLbl2.textColor = kRGB(100, 99, 104);
    detailLbl2.font = kAppFont(Home_Small_Size);
    detailLbl2.textAlignment = NSTextAlignmentRight;
    detailLbl2.text = [_currentDic valueForKey:@"InspectItemName"];
    [_headerView addSubview:detailLbl2];
    
    UIView *lineView2 = [[UIView alloc] init];
    lineView2.frame = CGRectMake(0.0f, 54.0f*3.0f-0.5f, kDeviceWidth, 0.5f);
    lineView2.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView2];
    
    
    //_detailLbl.text = [tempDic valueForKey:@"unitName"];
    //_detailLbl2.text = [tempDic valueForKey:@"projectName"];
    
    UILabel *lbl3 = [[UILabel alloc] init];
    lbl3.frame = CGRectMake(10.0, lineView2.bottom+(54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl3.font = kAppFont(Home_Small_Size+2.0f);
    lbl3.textColor = kRGB(205, 206, 207);;
    lbl3.text = @"所属公司";
    [_headerView addSubview:lbl3];
    
    
    //UIImageView *arrowImageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    //arrowImageView0.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, (54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[_headerView addSubview:arrowImageView0];
    
    UILabel *detailLbl3 = [[UILabel alloc] init];
    detailLbl3.frame = CGRectMake(lbl3.right+5.0f, lineView2.bottom+(54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl3.width-5.0f-10.0f, Home_Big_Size);
    detailLbl3.textColor = kRGB(100, 99, 104);
    detailLbl3.font = kAppFont(Home_Small_Size);
    detailLbl3.textAlignment = NSTextAlignmentRight;
    detailLbl3.text = [_InspectOrgAndProjectDic valueForKey:@"unitName"];
    [_headerView addSubview:detailLbl3];
    
    UIView *lineView3 = [[UIView alloc] init];
    lineView3.frame = CGRectMake(0.0f, 54.0f*4.0f-0.5f, kDeviceWidth, 0.5f);
    lineView3.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView3];
    
    
    
    UILabel *lbl4 = [[UILabel alloc] init];
    lbl4.frame = CGRectMake(10.0, lineView3.bottom+(54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl4.font = kAppFont(Home_Small_Size+2.0f);
    lbl4.textColor = kRGB(205, 206, 207);;
    lbl4.text = @"所属项目部";
    [_headerView addSubview:lbl4];
    
    
    //UIImageView *arrowImageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    //arrowImageView0.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, (54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[_headerView addSubview:arrowImageView0];
    
    UILabel *detailLbl4 = [[UILabel alloc] init];
    detailLbl4.frame = CGRectMake(lbl4.right+5.0f, lineView3.bottom+(54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl4.width-5.0f-10.0f, Home_Big_Size);
    detailLbl4.textColor = kRGB(100, 99, 104);
    detailLbl4.font = kAppFont(Home_Small_Size);
    detailLbl4.textAlignment = NSTextAlignmentRight;
    detailLbl4.text = [_InspectOrgAndProjectDic valueForKey:@"projectName"];;
    [_headerView addSubview:detailLbl4];
    
    UIView *lineView4 = [[UIView alloc] init];
    lineView4.frame = CGRectMake(0.0f, 54.0f*5.0f-0.5f, kDeviceWidth, 0.5f);
    lineView4.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView4];
    
    
    
    
    UILabel *lbl5 = [[UILabel alloc] init];
    lbl5.frame = CGRectMake(10.0, lineView4.bottom+(54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl5.font = kAppFont(Home_Small_Size+2.0f);
    lbl5.textColor = kRGB(205, 206, 207);;
    lbl5.text = @"检查类型";
    [_headerView addSubview:lbl5];
    
    
    //UIImageView *arrowImageView0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    //arrowImageView0.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, (54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    //[_headerView addSubview:arrowImageView0];
    
    UILabel *detailLbl5 = [[UILabel alloc] init];
    detailLbl5.frame = CGRectMake(lbl5.right+5.0f, lineView4.bottom+(54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl5.width-5.0f-10.0f, Home_Big_Size);
    detailLbl5.textColor = kRGB(100, 99, 104);
    detailLbl5.font = kAppFont(Home_Small_Size);
    detailLbl5.textAlignment = NSTextAlignmentRight;
    detailLbl5.text = [_checkDic valueForKey:@"Name"];
    [_headerView addSubview:detailLbl5];
    
    UIView *lineView5 = [[UIView alloc] init];
    lineView5.frame = CGRectMake(0.0f, 54.0f*6.0f-0.5f, kDeviceWidth, 0.5f);
    lineView5.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView5];
    
    
    
    
    UILabel *lbl6 = [[UILabel alloc] init];
    lbl6.frame = CGRectMake(10.0, lineView5.bottom+(54-(Home_Small_Size+2.0f))/2.0f, 100, Home_Small_Size+2.0f);
    lbl6.font = kAppFont(Home_Small_Size+2.0f);
    lbl6.textColor = kRGB(205, 206, 207);;
    lbl6.text = @"整改截止日期";
    [_headerView addSubview:lbl6];
    
    
    UIImageView *arrowImageView6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"02jiantou-"]];
    arrowImageView6.frame = CGRectMake(kDeviceWidth-10.0f/2.0f-10.0f, lineView5.bottom+(54-19.0f/2.0f)/2.0f, 10.0f/2.0f, 19.0f/2.0f);
    [_headerView addSubview:arrowImageView6];
    
    detailLbl6 = [[UILabel alloc] init];
    detailLbl6.frame = CGRectMake(lbl6.right+5.0f, lineView5.bottom+(54-Home_Big_Size)/2.0f, kDeviceWidth-10.0f-lbl6.width-5.0f-arrowImageView6.width-20.0f, Home_Big_Size);
    detailLbl6.textColor = kRGB(100, 99, 104);
    detailLbl6.font = kAppFont(Home_Small_Size);
    detailLbl6.textAlignment = NSTextAlignmentRight;
    detailLbl6.text = _dateStr;
    [_headerView addSubview:detailLbl6];
    
    UIView *lineView6 = [[UIView alloc] init];
    lineView6.frame = CGRectMake(0.0f, 54.0f*7.0f-0.5f, kDeviceWidth, 0.5f);
    lineView6.backgroundColor = kGreenColor;
    [_headerView addSubview:lineView6];
    
    
    UIControl *dateControl = [[UIControl alloc] init];
    dateControl.frame = CGRectMake(0.0f, lineView5.bottom, kDeviceWidth, 54.0f);
    dateControl.backgroundColor = [UIColor clearColor];
    [dateControl addTarget:self action:@selector(showDateView) forControlEvents:UIControlEventTouchUpInside];
    [_headerView addSubview:dateControl];
    
}

- (void)showDateView{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    _datePicker = [[UIDatePicker alloc] init];
    _datePicker.datePickerMode = UIDatePickerModeDate;
    NSDate *afterDate = [NSDate dateWithTimeIntervalSinceNow:3*24*60*60];
    _datePicker.minimumDate = afterDate;//[NSDate date];
    _datePicker.frame = CGRectMake(0.0f, self.view.height-200.0f, kDeviceWidth, 200.0f);
    _datePicker.backgroundColor = kDefaultBackgroundColor;
    [self.view addSubview:_datePicker];
    
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    _dateTopView = [[UIView alloc] init];
    _dateTopView.backgroundColor = kWhiteColor;
    _dateTopView.frame = CGRectMake(-0.5f, self.view.height-_datePicker.height-40.0f, kDeviceWidth+1.0f, 40.0f);
    _dateTopView.layer.borderColor = kGreenColor.CGColor;
    _dateTopView.layer.borderWidth = 0.5f;
    [self.view addSubview:_dateTopView];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [sureBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = kAppFont(Home_Big_Size);
    sureBtn.frame = CGRectMake(kDeviceWidth-40.0f-16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
    [sureBtn addTarget:self action:@selector(sureBtnAcion) forControlEvents:UIControlEventTouchUpInside];
    [_dateTopView addSubview:sureBtn];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = kAppFont(Home_Big_Size);
    cancleBtn.frame = CGRectMake(16.0f, (40-Home_Big_Size)/2.0f, 40.0f, Home_Big_Size);
    [cancleBtn addTarget:self action:@selector(cancleBtnAcion) forControlEvents:UIControlEventTouchUpInside];
    [_dateTopView addSubview:cancleBtn];
}

- (void)sureBtnAcion
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 格式化日期格式
    formatter. dateFormat = @"yyyy-MM-dd" ;
    _dateStr = [formatter stringFromDate:_datePicker.date];
    NSLog(@"=====%@", _dateStr);
    
    detailLbl6.text = _dateStr;
    
    
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
    
    //[_myTable reloadData];
}

- (void)cancleBtnAcion
{
    [_datePicker removeFromSuperview];
    _datePicker = nil;
    [_dateTopView removeFromSuperview];
    _dateTopView = nil;
}



#pragma mark  ************************* UITableViewDataSource **************************************
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    id tempId = [_currentDic valueForKey:@"InspectContentList"];
    if ([tempId isKindOfClass:[NSString class]]) {
        if ([tempId isEqualToString:@""]) {
            return 0;
        }
    }
    
    if (_dataArray != nil && _dataArray.count > 0) {
        return _dataArray.count;
    }
    return 0.0f;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell_house_History";
    CheckDetailCell *cell = (CheckDetailCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        cell = [[CheckDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *tempDic = [_dataArray objectAtIndex:indexPath.row];
    [cell showWithData:tempDic];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (40*4+10);//(10*2+6*2+(Home_Small_Size+2)*3.0f);
}


#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //NSArray *tempArray = [_currentDic objectForKey:@"InspectContentList"];
    NSDictionary *tempDic = [_dataArray objectAtIndex:indexPath.row];
    if ([tempDic valueForKey:@"MaxPoints"] > 0) {
        WriteCheckItemDetailViewController *checkVC = [[WriteCheckItemDetailViewController alloc] initWithID:[[tempDic valueForKey:@"InspectContentID"] intValue] data:tempDic];
        checkVC.delegate = self;
        [self.navigationController pushViewController:checkVC animated:YES];
    }
    
}

- (void)passValue:(NSDictionary *)value
{
    /*
     _currentPonints,@"WriteDetail_KouFen_Str",
     _currentRiskDic,@"WriteDetail_RiskLevel_Dic",
     _inputField.text,@"WriteDetail_MiaoShu_Str",
     _imageDataArray,@"WriteDetail_ImageData_List",
     */
    
    /*
     
     [dic setValue:@"无" forKey:@"JianChaMiaoShu"];
     [dic setValue:@"0" forKey:@"KouFen"];
     [dic setValue:@"" forKey:@"RiskLevel_Dic"];
     [dic setValue:@"" forKey:@"Image_List"];
     
     */
    NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:_dataArray];
    for (int i = 0; i < _dataArray.count; i ++) {
        //NSDictionary *tempD = [_dataArray objectAtIndex:i];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[_dataArray objectAtIndex:i]];
        if ([[dic valueForKey:@"InspectContentID"] intValue] == [[value valueForKey:@"InspectContentID"] intValue]) {
            //if ([[dic valueForKey:@"InspectContentID"] isEqualToString:[value valueForKey:@"InspectContentID"]]) {
            [dic setValue:[value valueForKey:@"WriteDetail_KouFen_Str"] forKey:@"KouFen"];
            [dic setValue:[value valueForKey:@"WriteDetail_MiaoShu_Str"] forKey:@"JianChaMiaoShu"];
            [dic setObject:[value objectForKey:@"WriteDetail_RiskLevel_Dic"] forKey:@"RiskLevel_Dic"];
            [dic setObject:[value objectForKey:@"WriteDetail_ImageData_List"] forKey:@"ImageData_List"];
            
            [tempArray replaceObjectAtIndex:i withObject:dic];
        }
    }
    
    _dataArray = tempArray;
    [_myTable reloadData];
    /*
     for (int i = 0; i < _pointsArray.count; i ++) {
     NSDictionary *tempD = [_pointsArray objectAtIndex:i];
     if ([[tempD valueForKey:@"InspectContentID"] intValue] == [[value valueForKey:@"InspectContentID"] intValue]) {
     //if ([[tempD valueForKey:@"InspectContentID"] isEqualToString:[value valueForKey:@"InspectContentID"]]) {
     [_pointsArray replaceObjectAtIndex:i withObject:value];
     }
     else{
     [_pointsArray addObject:value];
     }
     }
     */
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
